package com.start.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.start.admin.entity.StartSysUserManageDept;
import com.start.admin.mappers.SysUserManageDeptMapper;
import com.start.admin.service.StartSysUserManageDeptService;
import com.start.admin.vo.StartSysUserManageDeptVo;
import com.start.common.constant.StartConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StartSysUserManageDeptServiceImpl extends ServiceImpl<SysUserManageDeptMapper, StartSysUserManageDept> implements StartSysUserManageDeptService {
    @Override
    public Page<StartSysUserManageDeptVo> pageUserManage(Page<StartSysUserManageDeptVo> page, Wrapper<StartSysUserManageDeptVo> wrapper) {
        Page<StartSysUserManageDeptVo> resultPage = baseMapper.pageUserManage(page, wrapper);
        if (resultPage.getRecords().isEmpty()) return resultPage;
        for (StartSysUserManageDeptVo vo : resultPage.getRecords()) {
            vo.setStartUserType(StartConstant.ClientUserType.ADMIN_USER);
        }
        return resultPage;
    }

    @Override
    public List<StartSysUserManageDept> listByUserId(String userId) {
        LambdaQueryWrapper<StartSysUserManageDept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StartSysUserManageDept::getUserId, userId);
        return list(queryWrapper);
    }

    @Override
    public List<StartSysUserManageDept> listByDeptIdAndManageLevel(String deptId, String manageLevel) {
        LambdaQueryWrapper<StartSysUserManageDept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StartSysUserManageDept::getDeptId, deptId);
        queryWrapper.eq(!StringUtils.isEmpty(manageLevel), StartSysUserManageDept::getManageLevel, manageLevel);
        return list(queryWrapper);
    }
}
